package com.immunology.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.immunology.model.MappingPages;

public class LoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public LoginServlet() {
	}

	@Override
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.sendRedirect("");
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		String login = request.getParameter("login");
		String password = request.getParameter("password");

		if (login.equals("admin") && password.equals("adminadmin")) {
			// getServletContext().getRequestDispatcher(MappingPages.ADMIN_JSP)
			// .forward(request, response);
			response.sendRedirect(MappingPages.ADMIN_PAGE);
		} else {
			response.sendRedirect(MappingPages.USER_PAGE);
		}
		/*
		 * User user = null; String login = (String)
		 * request.getParameter("login"); String password = (String)
		 * request.getParameter("password"); SecurityServiceGeneric
		 * securityService = new SecurityService(); boolean isValidLogin = new
		 * LoginFieldValidator().emailValidate(login); if (isValidLogin) { user
		 * = securityService.getUser(login, password); } if (user != null &&
		 * user.getVisible() == true) {
		 * request.getSession().setAttribute(AttributeContent.USER, user); if
		 * (Role.ADMIN == user.getRole()) {
		 * response.sendRedirect(MappingPages.ADMIN_PAGE); } else if (Role.USER
		 * == user.getRole()) { response.sendRedirect(MappingPages.USER_PAGE +
		 * user.getId()); } } else { showErrorMessage(request, user);
		 * getServletContext().getRequestDispatcher(MappingPages.LOGIN_JSP)
		 * .forward(request, response);
		 * getServletContext().removeAttribute(AttributeContent.ERROR_LOGIN); }
		 */
	}

	/*
	 * private void showErrorMessage(HttpServletRequest request, User user) {
	 * getServletContext().setAttribute(AttributeContent.ERROR_LOGIN,
	 * "Wrong e-mail or password"); if (user != null && user.getVisible() ==
	 * false) { getServletContext().setAttribute(AttributeContent.ERROR_LOGIN,
	 * "You are baned"); LOG.info("Banned user wants to connect"); } }
	 */
}
